package com.lemon.controller;

import com.lemon.domain.LogisticsPrice;
import com.lemon.domain.PageResult;
import com.lemon.domain.Result;
import com.lemon.service.LogisticsPriceService;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

/**
* 物流价格表(tb_logistics_price)表控制层
*
* @author xxxxx
*/
@RestController
    @RequestMapping("/logisticsPrice")
public class LogisticsPriceController {

    @Autowired
    private LogisticsPriceService  logisticsPriceService;

    @GetMapping
    public Result getPage(Integer page, Integer pageSize, Integer category,Integer logisticsCompanyId){
        PageResult pageResult = logisticsPriceService.getPage(page, pageSize, category,logisticsCompanyId);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result add(@RequestBody LogisticsPrice logisticsPrice){
        logisticsPrice.setCreateTime(LocalDateTime.now());
        return logisticsPriceService.save(logisticsPrice)?Result.success():Result.error("添加失败");
    }

    @PutMapping
    public Result update(@RequestBody LogisticsPrice logisticsPrice){
        logisticsPrice.setUpdateTime(LocalDateTime.now());
        return logisticsPriceService.updateById(logisticsPrice)?Result.success():Result.error("修改失败");
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id){
        return logisticsPriceService.removeById(id)?Result.success():Result.error("删除失败");
    }
}
